package cn.nr19.jian

import cn.nr19.jian.factory.EONFactory
import cn.nr19.jian.factory.TokenFactory
import cn.nr19.jian.`object`.EON
import cn.nr19.jian.`object`.JianLei
import cn.nr19.jian.token.ARRNode
import cn.nr19.jian.token.EONNode
import java.io.BufferedReader
import java.io.FileReader
import java.io.IOException
import java.lang.StringBuilder


fun main() {


    val str = StringBuilder()
    /*try {

        BufferedReader(FileReader("D:\\My Studio\\browser\\jian\\src\\main\\java\\cn\\nr19\\jian\\ttt.txt")).use { reader ->
            var line: String?
            while (reader.readLine().also { line = it } != null) {
                str.append(line)
            }
        }
    } catch (e: IOException) {
        e.printStackTrace()
    }*/

    val t = """var a="aaadddbb"
a = a.文本替换3("d","n")
输出(a)
    """.trimMargin()

  test(t)

}
fun arrr(e : ARRNode){
    for (data in e.datas) {
        J2Utils.log(data.nodeType(),data)
    }
}

fun eon(str: String){
    val time = System.currentTimeMillis()
    EONFactory.start(str) {
        J2Utils.log("失败", it)
    }.let {
        J2Utils.log("aaaa",System.currentTimeMillis() - time)
        J2Utils.log("bb",it?.datas?.size,it)
    }
}

fun test(str : String){
    val time = System.currentTimeMillis()
    val result = Jian.p(str,JianLei(),object : OnJianParserListener{
        override fun onLangError(msg: String) {
            J2Utils.log("语法错误",msg)
        }

        override fun onParserError(msg: String) {
            J2Utils.log("解析错误",msg)
        }

        override fun log(msg: String, level: Int, msg2: String, code: String) {
            J2Utils.log("输出",msg)
        }


    })


    J2Utils.log("结果：",result,System.currentTimeMillis() - time)

}

